{-# LANGUAGE OverloadedStrings #-}
module Pages.Formlets(labelled, inputProgram) where

import Control.Applicative
import State.Database(Program(..), Language(..))
import Text.Blaze.Html5.Formlets
import Text.Blaze.Html5(p, toHtml, span, div)
import Prelude hiding(span, div)

-- | A simple HTML wrapping putting a label beside a formlet
labelled :: String -> Html5Form m a -> Html5Form m a
labelled lbl form = plug (div . (span (toHtml lbl) >>)) form

-- | A formlet representing the programming language selector
inputProgram :: (Applicative m, Monad m) => Html5Formlet m Program
inputProgram initial =
    let languageChoice = [(Haskell, "Haskell"),(Cpp, "C++"),(Java, "Java"),(CSharp, "C#")] in
    Program
    <$> plug p (select languageChoice (programLanguage <$> initial))
    <*> plug p (textarea (Just 20) (Just 40) (programCode <$> initial))
